import employeesData from '@/api/constant/employees.js'
import store from '@/store'
import { log } from 'loglevel'
export default {
  // 指令名:{生命周期}
  //   图片出错的自定义指令，使用：  v-imgError="默认图片地址"
  imgError: {
    inserted(dom, obj) {
      dom.src = dom.src || obj.value
      dom.onerror = function() {
        dom.src = obj.value
      }
    },
    componentUpdated(dom, obj) {
      dom.src = dom.src || obj.value
    },
    unbind(dom) {
      dom.onerror = null
    }
  },
  xxx: {},
  formatterFormOf: {
    inserted(dom, obj) {
      const temp = employeesData.hireType.find((item) => {
        return item.id === obj.value
      })
      dom.innerText = temp ? temp.value : '-'
    },
    componentUpdated(dom, obj) {
      const temp = employeesData.hireType.find((item) => {
        return item.id === obj.value
      })
      dom.innerText = temp ? temp.value : '-'
    }
  },
  setButtonPower: {
    inserted(dom, obj) {
      console.log('setButtonPower', store.state.user.userInfo.roles.points, obj)
      if (!store.state.user.userInfo.roles.points.includes(obj.value)) {
        dom.style.display = 'none'
      }
    },
    componentUpdated(dom, obj) {
      if (!store.state.user.userInfo.roles.points.includes(obj.value)) {
        dom.style.display = 'none'
      }
    }
  }
}
